package model

import "apiserver/pkg/constvar"

type College struct {
	CollegeId   int    `json:"collegeId" gorm:"column:college_id"`
	CollegeName string `json:"collegeName" gorm:"column:college_name"`
}

func (cg *College) TableName() string {
	return "bnycgk_colleges"
}

//获取院校列表
func GetCollegeList(offset, limit int) ([]*College, int, error) {
	if limit == 0 {
		limit = constvar.DefaultLimit
	}

	colleges := make([]*College, 0)
	count := 0

	if err := DB.Self.Model(College{}).Count(&count).Error; err != nil {
		return colleges, count, err
	}

	if err := DB.Self.Offset(offset).Limit(limit).Order("rank is null, rank asc").Find(&colleges).Error; err != nil {
		return colleges, count, err
	}

	return colleges, count, nil

}
